import concurrent.futures
import threading

global_variable = 0
lock = threading.Lock()

def increment_global_variable():
    global global_variable  
    with lock:
        global_variable += 1
        print(f"variable increment: {global_variable}")

def thread_function_use_lock():
    with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
        futures = [executor.submit(increment_global_variable) for _ in range(10)]
        concurrent.futures.wait(futures)
        
    print(f"Global variable after increment_lock: {global_variable}")


if __name__ == "__main__":
    # 数据共享方法
    # 使用全局变量和锁来确保线程安全
    thread_function_use_lock()